<template>
  <div class="zs-table-page-container">
    <SearchTabTime :tabList="tabList" :curTabIndex="curTabIndex" @onChange="changeTab" :tag="`${tag} 更新`"></SearchTabTime>
    <div class="zs-card zs-table-page-content" v-loading="loading">
      <BusinessTable v-if="curTabIndex == 0" :tableData="tableData" :updateDate="updateDate"
        :tabPermi="tabList[curTabIndex].permi"></BusinessTable>
      <WorkTable v-if="curTabIndex == 1" :tableData="tableData" :updateDate="updateDate"
        :tabPermi="tabList[curTabIndex].permi"></WorkTable>
      <!-- <PropertyTable v-if="curTabIndex == 2" :tableData="tableData" :updateDate="updateDate"
        :tabPermi="tabList[curTabIndex].permi"></PropertyTable> -->
      <FlatsTable v-if="curTabIndex == 2" :tableData="tableData" :updateDate="updateDate"
        :tabPermi="tabList[curTabIndex].permi"></FlatsTable>
      <RestaurantTable v-if="curTabIndex == 3" :tableData="tableData" :updateDate="updateDate"
        :tabPermi="tabList[curTabIndex].permi"></RestaurantTable>
    </div>
  </div>
</template>
<script setup>
import SearchTabTime from '@/DbComponents/searchTabTime'
import BusinessTable from '@/views/Manage/Business/projectTable.vue'
import WorkTable from '@/views/Manage/Work/projectTable.vue'
// import PropertyTable from '@/views/Manage/Property/projectTable.vue'
import FlatsTable from '@/views/Manage/Flats/projectTable.vue'
import RestaurantTable from '@/views/Manage/Restaurant/projectTable.vue'
import dbPublicApi from '@/api/dbPublic'
import { ref } from 'vue'

// const tabList = ref([{ label: '商业', value: '商业', permi: 'p_btn_901_jingyingxiangmu_shangye' }, { label: '办公', value: '办公', permi: 'p_btn_901_jingyingxiangmu_bangong' }, { label: '产业', value: '产业', permi: 'p_btn_901_jingyingxiangmu_chanye' }, { label: '酒寓', value: '酒寓', permi: 'p_btn_901_jingyingxiangmu_jiuyu' }, { label: '餐饮', value: '餐饮', permi: 'p_btn_901_jingyingxiangmu_canyin' }])
const tabList = ref([{ label: '商业', value: '商业', permi: 'p_btn_901_jingyingxiangmu_shangye' }, { label: '产办', value: '产办', permi: 'p_btn_901_jingyingxiangmu_bangong' }, { label: '酒寓', value: '酒寓', permi: 'p_btn_901_jingyingxiangmu_jiuyu' }, { label: '餐饮', value: '餐饮', permi: 'p_btn_901_jingyingxiangmu_canyin' }])
const curTabIndex = ref(-1)

let tag = ref('')
const loading = ref(true)
const tableData = ref([])
const updateDate = ref('')
const getDate = async (menuKey) => {
  await dbPublicApi.queryDataTimeApi(menuKey).then((res) => {
    if (res.data.code == 200) {
      tag.value = res.data.message
      updateDate.value = res.data.data
    }
  })
}
const getList = async () => {
  await dbPublicApi.queryProjectPcApi({ dataTime: updateDate.value, resourceKey: tabList.value[curTabIndex.value].permi }).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data
    }
  })
}
const getTabIndex = async () => {
  let list = await JSON.parse(localStorage.getItem('portalResourceList'))
  if (!list) { return false }
  for (let [index, tab] of tabList.value.entries()) {
    if (list.indexOf(tab.permi) > -1) {
      curTabIndex.value = index
      break;
    }
  }
}
const changeTab = async (data) => {
  loading.value = true
  curTabIndex.value = data.data
  tableData.value = []
  await getDate(tabList.value[curTabIndex.value].permi)
  await getList()
  loading.value = false
}
const init = async () => {
  await getTabIndex()
  if (curTabIndex.value == -1) {
    loading.value = false
    return false
  }
  await getDate(tabList.value[curTabIndex.value].permi)
  await getList()
  loading.value = false
}
init()


</script>


<style scoped lang="scss"></style>
